{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE KindSignatures        #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE EmptyDataDecls        #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE FlexibleInstances     #-}

module Language.HtmlParsec.Syntax where

import Generics.MultiRec.TH.Alt
import Generics.MultiRec.Base

-- ein paar Synonyme für besser Lesbarkeit
type Name = String
type Value = String
type Action = String
type Level = Int

-- die Syntax
data Position = P !Int !Int deriving Show

data Html = Html Position [Element] deriving Show

data Element = Heading Position Level String 
             | Plain Position String 
             | Var Position String
             | Paragraph Position [Element] 
             | Form Position Action [Field]
             | UnknownTag Position         -- ist erforderlich um unbekannte Tags ignorieren zu koennen
             deriving Show

data Field = Textfield Position Name Value 
           | Radio Position Name Value 
           | Submit Position Name 
           | Reset Position Name
           | UnknownFieldType Position     -- ist erforderlich um unbekannte Field Typen ignorieren zu koennen
           deriving Show


data HTML :: * -> * where
  TheHtml  ::  HTML Html
  TheElement  ::  HTML Element
  TheElementList  ::  HTML ([] Element)
  TheField  ::  HTML Field


$(deriveEverything
  (DerivOptions
    [ ( [t| Html |] ,"TheHtml")
    , ( [t| Element |] ,"TheElement")
    , ( [t| [] Element |] ,"TheElementList")
    , ( [t| Field |] ,"TheField")
    ]
   "HTML"
   (\t c -> "CONSTRUCTOR_" ++ t ++ "_" ++ c)
   "HTMLPF"
   True
   Balanced
  )
 )

type instance PF HTML = HTMLPF
